package com.teamcenter.rac.massupdate.validators;

import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.massupdate.Activator;
import com.teamcenter.rac.massupdate.model.UpdateJobModel;
import com.teamcenter.rac.massupdate.ui.Messages;
import com.teamcenter.rac.massupdate.utils.MassUpdateHelper;
import com.teamcenter.rac.massupdate.utils.SourceHelper;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.views.properties.IPropertySource;

public class MarkupExistsValidator
  extends AbstractMassUpdateValidator
{
  private UpdateJobModel m_updateJobModel;
  
  public MarkupExistsValidator(UpdateJobModel paramUpdateJobModel)
  {
    this.m_updateJobModel = paramUpdateJobModel;
  }
  
  public IStatus validate(Object paramObject)
  {
    if (paramObject == null)
    {
      this.m_updateJobModel.setMarkupAllowed(true);
    }
    else if ((paramObject instanceof IPropertySource))
    {
      IPropertySource localIPropertySource = (IPropertySource)paramObject;
      boolean bool = false;
      TCComponent localTCComponent1 = SourceHelper.getAssociatedComponent(localIPropertySource, getTCSession());
      if ((localTCComponent1 instanceof TCComponentItemRevision)) {
        bool = MassUpdateHelper.isChangeItemRevision((TCComponentItemRevision)localTCComponent1);
      }
      if (bool)
      {
        TCComponent localTCComponent2 = MassUpdateHelper.getMarkupObject((TCComponentItemRevision)localTCComponent1);
        if ((localTCComponent2 != null) && (!this.m_updateJobModel.isAddToMarkup()))
        {
          this.m_updateJobModel.setMarkupAllowed(false);
          return new Status(2, Activator.getDefault().getBundleSymbolicName(), Messages.Validator_MarkupExists);
        }
        this.m_updateJobModel.setMarkupAllowed(true);
        return Status.OK_STATUS;
      }
      return new Status(4, Activator.getDefault().getBundleSymbolicName(), Messages.Validator_SelectedItemNotAChangeItem);
    }
    return Status.OK_STATUS;
  }
}